﻿@model PermissionMappingModel
<div class="layui-card" lay-filter="">
    <div class="layui-card-header layuiadmin-card-header-auto">
        <button class="layui-btn" lay-submit lay-filter="btn_save">确认保存</button>
    </div>
    <div class="layui-card-header">
        @T("Admin.Configuration.ACL.Permission")
    </div>
    <div class="layui-card-body layui-form">
        <table class="layui-table">
            <thead>
                <tr>
                    <td>权限</td>
                    @foreach (var cr in Model.AvailableUserRoles)
                    {
                        <td>@cr.Name</td>
                    }
                </tr>
            </thead>
            <tbody>
                @{
                    bool altRow = true;
                }
                @foreach (var pr in Model.AvailablePermissions)
                {
                    altRow = !altRow;
                    <tr>
                        <td>
                            <span>@pr.Name</span>
                        </td>
                        @foreach (var cr in Model.AvailableUserRoles)
                        {
                            var allowed = Model.Allowed.ContainsKey(pr.SystemName) && Model.Allowed[pr.SystemName][cr.Id];
                            <td>
                                <input id="@(cr.Id)" type="checkbox" value="@(pr.SystemName)" name="allow_@(cr.Id)" @(allowed ? " checked=checked" : null) lay-skin="switch" lay-filter="enabled" lay-text="启用|停用" />
                            </td>
                        }
                    </tr>
                }
            </tbody>
        </table>
    </div>
</div>
<script>
    layui.config({
        base: '../../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
        }).use(['index', 'set'], function () {
        var $ = layui.$
            , form = layui.form
            , active = {}

        //监听指定开关
         form.on('switch(enabled)', function (obj) {
            var check = obj.elem.checked;
            $.post('@Url.Action("PermissionsEnabled")', { Id: this.id,Value:this.value, checked: check });

        });
    });
</script>